package cn.edu.sgu.www.pms.service.impl;

import cn.edu.sgu.www.pms.entity.Table;
import cn.edu.sgu.www.pms.mapper.TableMapper;
import cn.edu.sgu.www.pms.service.TableService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Service
public class TableServiceImpl implements TableService {

    private final TableMapper tableMapper;

    @Autowired
    public TableServiceImpl(TableMapper tableMapper) {
        this.tableMapper = tableMapper;
    }

    @Override
    public List<String> getTableNames(String databaseName) {
        return tableMapper.getTableNames(databaseName);
    }

    @Override
    public List<Table> selectByDatabase(String databaseName) {
        QueryWrapper<Table> queryWrapper = new QueryWrapper<>();

        queryWrapper.eq("table_schema", databaseName);

        return tableMapper.selectList(queryWrapper);
    }

}
